﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PBOffice.Models;

namespace PBOffice.BLL
{
    public class NameNumOverOff
    {
        public List<NameNumOverOff1> GetByNameAndNum(string num, string name, int pageIndex, int pageSize)
        {
            List<NameNumOverOff1> list = new List<NameNumOverOff1>();
            List<StaffExp> exp = new StaffExpManager().GetAllByNameAndMonth(num, name, pageIndex, pageSize);
            foreach (StaffExp item in exp)
            {
                NameNumOverOff1 kao = new NameNumOverOff1();
                double off = GetOffWorkContHours(item.Num.ToString(), item.StfName);
                double over = GetOverWorkContHours(item.Num.ToString(), item.StfName);
                kao.Name = item.StfName;
                kao.Num = item.Num;
                kao.Off = off;
                kao.Over = over;
                list.Add(kao);
            }
            return list;
        }
        private double GetOffWorkContHours(string month, string name)
        {
            double num = 0;
            List<OffWork> offList = new OffWorkManager().GetOffWorkByNameAndMonth(month, name);
            foreach (OffWork item in offList)
            {
                num += item.Hours;

            }
            return num;
        }
        private double GetOverWorkContHours(string month, string name)
        {
            double num = 0;
            List<OverWork> overList = new OverWorkManager().GetOverWorkByNameAndMonth(month, name);
            foreach (OverWork item in overList)
            {
                num += item.Hours;

            }
            return num;
        }
    }
}
